package com.sojson.controller.po.pay.ali;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.controller.po.pay.param.verify.PayParamVerify;
import com.sojson.dao.OrderChildDao;
import com.sojson.dao.OrderDao;
import com.sojson.dao.OrderDepositDao;
import com.sojson.result.Result;
import com.sojson.service.pay.ali.PayAliAppService;
import com.sojson.util.pay.ali.bean.AliResult;

import io.swagger.annotations.Api;

/**
 * 支付宝App支付控制器
 * 
 * @author liu
 * @date 2021-03-24
 */
@Api(tags = "支付宝App支付管理")
// @RestController
@RequestMapping(value = "/payAliApp")
public class PayAliAppController {

    @Autowired
    private PayAliAppService payAliAppService;
    @Resource
    private OrderDao orderDaoImpl;
    @Resource
    private OrderChildDao orderChildDaoImpl;
    @Resource
    private OrderDepositDao orderDepositDaoImpl;

    /**
     * 商城购物车调起支付
     * 
     * @param nos
     * @return
     * @throws Exception 
     */
    @PostMapping("/goodsShop/{nos}")
    @PreAuthorize("@ss.login()")
    public Object goodsShop(@PathVariable String[] nos) throws Exception {
        // 校验参数
        Result<?> paramResult = PayParamVerify.goodsShop(nos);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        AliResult result = payAliAppService.goodsShop(nos);

        return Result.success(result);
    }

    /**
     * 诚意金调起支付
     * 
     * @param orderId
     * @return 
     * @throws Exception 
     */
    @PostMapping("/deposit/{orderId}")
    @PreAuthorize("@ss.login()")
    public Object deposit(@PathVariable Integer orderId) throws Exception {
        // 校验参数
        Result<?> paramResult = PayParamVerify.deposit(orderId);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        AliResult result = payAliAppService.deposit(orderId);

        return Result.success(result);
    }

}